package com.cn.ssm.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.cn.ssm.model.Usert;
import com.cn.ssm.service.UsertService;

@Controller
@RequestMapping("/usert")
public class UsertController {

   @Resource
   UsertService usertService;
   
   @RequestMapping("/init")
   public ModelAndView initUserInfo(){
	   System.out.println("initUserInfo-----ʼ");
	   ModelAndView mv=new ModelAndView("/usert/login");
	   Usert usert= usertService.getUserById(1);
	   mv.addObject("usert", usert);
	   System.out.println("initUserInfo----");
	   return mv;
   }
   
   
   @RequestMapping("login")
   public ModelAndView userValid(@RequestParam("username") String username,
		                   		 @RequestParam("pw") String pw ,
		                   		 HttpServletRequest request
		                    ){
	   System.out.println("userValid-----");
	   Usert usert= usertService.getUserById(1);
	   ModelAndView mv=new ModelAndView("/main");
	   mv.addObject("username", username);
	   mv.addObject("pw", pw);
	   System.out.println("userValid-----");
	   return mv;
   }
}
